// DP, time limit exceeded
#include <cmath>
#include <iostream>
using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;

    int a[n], b[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];

    for (int i = 0; i < n; i++)
        cin >> b[i];

    long f[2 * n + 1];
    for (int i = 0; i <= 2 * n; i++)
        f[i] = 0;

    int maxI = 2 * n;

    for (int j = 0; j < n; j++) {
        for (int i = maxI; i >= b[j]; i--) {
            if (f[i - b[j]] + a[j] > f[i]) {
                f[i] = f[i - b[j]] + a[j];
                if (f[i] >= m)
                    maxI = i;
            }
        }
    }

    for (int i = 0; i <= 2 * n; i++)
        if (f[i] >= m) {
            cout << i << endl;
            return;
        }

    cout << -1 << endl;
}

int main() {
    int t;
    cin >> t;
    while (t-- > 0)
        solve();
    return 0;
}